package com.ly.core.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	
	/**
	 * 设置当前时间为当天的最初时间（即00时00分00秒）
	 * @param cal
	 * @return
	 */
	public static Calendar setStartDay(Calendar cal){
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal;
	}
	public static void copyYearMonthDay(Calendar destCal, Calendar sourceCal)
	  {
	    destCal.set(1, sourceCal.get(1));
	    destCal.set(2, sourceCal.get(2));
	    destCal.set(5, sourceCal.get(5));
	  }
	public static Calendar setEndDay(Calendar cal){
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal;
	}
	
	/**
	 * 格式化日期为MM/dd/yyyy hh:mm:ss a
	 * @return
	 */
	public static String formatEnDate(Date date){
		SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
		
		return sdf.format(date).replaceAll("上午", "AM").replaceAll("下午", "PM");
		
	}
	/**
	 * 格式化日期为
	 * @return
	 */
	public static String formatDate(Date date,String pattern){
		SimpleDateFormat sdf=new SimpleDateFormat(pattern);
		return sdf.format(date);
		
	}
}
